using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class RuleBookManager : MonoBehaviour
{
    public static RuleBookManager instance;
    
    public List<Sprite> pagesInRuleBook;

    public List<Sprite> pagesForTheDay = new List<Sprite>();

    public List<GameObject> clickablePartsGroupOnRuleBook;

    public int currentPage = 0;

    public bool isOnBigTable;

    public Button turnPageLeft;
    public Button turnPageRight;

    private void Awake()
    {
        instance = this;
    }

    private void Update()
    {
        isOnBigTable = GetComponent<DocumentsOnTable>().isOnBigTable;
        if (Input.GetKeyDown(KeyCode.R))
        {
            ChangePagesInRuleBook(3, 1, 2);
        }
    }

    public void ChangePagesInRuleBook(int page1, int page2, int page3)
    {
        //每天刷新rulebook中显示的页数
        pagesForTheDay[0] = pagesInRuleBook[page1];
        pagesForTheDay[1] = pagesInRuleBook[page2];
        pagesForTheDay[2] = pagesInRuleBook[page3];
        
        //重置CurrentPage，回到第一页，并且显示第一页
        currentPage = 0;
        gameObject.GetComponent<Image>().sprite = pagesForTheDay[currentPage];
        gameObject.GetComponent<DocumentsOnTable>().documentBig = pagesForTheDay[currentPage];
    }

    public void TurnPageRight()
    {
        if (currentPage == 2)
        {
            Debug.Log("this is the last page");
        }
        else
        {
            //同时更改当前Image中Sprite（翻页效果）以及DocumentBig中Sprite变量值（从小变大拖回来也会显示先前的）
            currentPage++;
            gameObject.GetComponent<Image>().sprite = pagesForTheDay[currentPage];
            gameObject.GetComponent<DocumentsOnTable>().documentBig = pagesForTheDay[currentPage];
        }
    }

    public void TurnPageLeft()
    {
        if (currentPage == 0)
        {
            Debug.Log("this is the first page");
        }
        else
        {
            //同时更改当前Image中Sprite（翻页效果）以及DocumentBig中Sprite变量值（从小变大拖回来也会显示先前的）
            currentPage--;
            gameObject.GetComponent<Image>().sprite = pagesForTheDay[currentPage];
            gameObject.GetComponent<DocumentsOnTable>().documentBig = pagesForTheDay[currentPage];
        }
    }
}
